<%@ page import="java.sql.*" %><%--
  Created by IntelliJ IDEA.
  User: 你
  Date: 2020/10/7
  Time: 8:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>201819101001张佳兴</title>
</head>
<body>
<%
    if (session.getAttribute("username") == null){
        out.print("你尚未登陆，3秒后跳转登陆页面");
        response.setHeader("refresh","3;url=login.jsp");
    }else {
        out.print("欢迎来到个人主页！<br>");
    }

    //加载数据库驱动
    Class.forName("com.mysql.jdbc.Driver");

    //建立数据库链接
    String url = "jdbc:mysql://localhost:3306/book";
    Connection connection = DriverManager.getConnection(url,"root","root");

    String sql = "select * from user";
    PreparedStatement ps = connection.prepareStatement(sql);

    ResultSet rs = ps.executeQuery();

    while (rs.next()){
        out.print(rs.getString("username")+"-"+rs.getString(3)+"<br>");

    }


%>
</body>
</html>
